| Total Complexity | 2 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | import {Observer} from '@enbock/state-value-observer/ValueObserver'; |
||
| 7 | |||
| 8 | export default class ModuleLoader { |
||
| 9 | moduleState: Observer<typeof React.Component | null>; |
||
| 10 | dictionary: LoadedModuleDictionary; |
||
| 11 | pathToRoot: string; |
||
| 12 | |||
| 13 | constructor(pathToRoot: string, moduleState: Observer<typeof React.Component | null>) { |
||
| 14 | 2 | this.moduleState = moduleState; |
|
| 15 | 2 | this.dictionary = {}; |
|
| 16 | 2 | this.pathToRoot = pathToRoot; |
|
| 17 | } |
||
| 18 | |||
| 19 | async loadModule(modulePath: string) { |
||
| 20 | let module: typeof React.Component; |
||
| 21 | |||
| 22 | 3 | if (!this.dictionary.hasOwnProperty(modulePath)) { |
|
| 23 | 2 | const filePath = (this.pathToRoot + modulePath + '.js').replace('.././', '../'); |
|
| 24 | 2 | module = (await import(filePath)).default as typeof React.Component; |
|
| 25 | 2 | this.dictionary[modulePath] = module; |
|
| 26 | } else { |
||
| 27 | 1 | module = this.dictionary[modulePath]; |
|
| 28 | } |
||
| 29 | |||
| 30 | 3 | this.moduleState.value = module; |
|
| 31 | } |
||
| 33 |